﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;

using DrugsShopManagement.DBCLASS;

namespace DrugsShopManagement
{
    public partial class FrmStoreManageDetail : Form
    {
        public FrmStoreManageDetail()
        {
            InitializeComponent();
        }
        Operator op = new Operator();
        private void FrmStoreManageDetail_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“drugsStoreRoom.StoreRoom”中。您可以根据需要移动或删除它。
            this.storeRoomTableAdapter.Fill(this.drugsStoreRoom.StoreRoom);
            tabControl1.TabPages[0].Show();

            DataTable dt1 = new DataTable();
            string sql_1 = "select drugsId 药品ID,drugsName 药品名称, drugsPY 拼音码, drugsSpecification 药品规格,drugsUnit 计量单位, drugsCount 库存数量,drugsStorePlace 库存地址,drugsRegNum 批准文号 ,drugsFactory 生产厂家,providerCompany 供应商,drugsUsefulDate 有效期,drugsInPrice 进货价格,drugsSalePrice 销售价格 from drugsStore   order by Id";
            dt1 = op.getDataTable(sql_1, "drugsStore ");
            dataGridView1.DataSource = dt1;

            DataTable dt2 = new DataTable();
            string sql_2 = "select b.drugsMin 库存下限值, a.drugsCount 库存数量,a.drugsStorePlace 库存地址,a.drugsId 药品ID,a.drugsName 药品名称, a.drugsPY 拼音码, a.drugsSpecification 药品规格,a.drugsUnit 计量单位,a.drugsRegNum 批准文号 ,a.drugsFactory 生产厂家,a.providerCompany 供应商,a.drugsUsefulDate 有效期,a.drugsInPrice 进货价格,a.drugsSalePrice 销售价格 from drugsstore a left outer join  drugswarning b on a.drugsid=b.drugsid where a.drugsCount<b.drugsMin   order by a.Id";
            dt2 = op.getDataTable(sql_2, "drugsStore ");
            dataGridView2.DataSource = dt2;

            DataTable dt3 = new DataTable();
            string sql_3 = "select drugsUsefulDate 有效期, drugsId 药品ID,drugsName 药品名称, drugsPY 拼音码, drugsSpecification 药品规格,drugsUnit 计量单位, drugsCount 库存数量,drugsStorePlace 库存地址,drugsRegNum 批准文号 ,drugsFactory 生产厂家,providerCompany 供应商,drugsInPrice 进货价格,drugsSalePrice 销售价格 from drugsstore where drugsUsefulDate<(select getdate())  order by Id";
            dt3 = op.getDataTable(sql_3, "drugsStore ");
            dataGridView3.DataSource = dt3;
           

        }

        private void buttonPrint1_Click(object sender, EventArgs e)
        {
            try
            {

                XtraReport report = new XtraReport();
                string path = System.IO.Directory.GetCurrentDirectory();
                report.LoadLayout(path + "..\\..\\..\\Reports\\库存单报表.repx");
                ReportPrintTool printTool = new ReportPrintTool(report);
                //DataTable dt = new DataTable();
                DataSet ds = new DataSet();
                //string sql = "select user_id 编号,user_no 用户工号, user_name 用户姓名, user_power 用户权限, user_descripe 用户描述, user_sort 序号 from users order by user_sort";
                //dt = op.getDataTable(sql, "users");
                string sql = "select *,getdate() from drugsStore where drugsStorePlace='" + comboBox1.Text + "' order by Id";
                ds = op.getDataSet(sql);
                //report.DataSource = dt;
                report.DataSource = ds;
                //printTool.ShowPreview();
                //printTool.ShowRibbonPreview(UserLookAndFeel.Default);
                printTool.ShowRibbonPreview();
            }
            catch (Exception ex)
            {
                MessageBox.Show("无法打开报表，详细信息：" + ex.ToString());
            }
        }

        private void buttonPrint2_Click(object sender, EventArgs e)
        {
            try
            {

                XtraReport report = new XtraReport();
                string path = System.IO.Directory.GetCurrentDirectory();
                report.LoadLayout(path + "..\\..\\..\\Reports\\库存单报表.repx");
                ReportPrintTool printTool = new ReportPrintTool(report);
                //DataTable dt = new DataTable();
                DataSet ds = new DataSet();
                //string sql = "select user_id 编号,user_no 用户工号, user_name 用户姓名, user_power 用户权限, user_descripe 用户描述, user_sort 序号 from users order by user_sort";
                //dt = op.getDataTable(sql, "users");
                string sql = "select b.drugsMin ,a.*,getdate() from drugsstore a left outer join  drugswarning b on a.drugsid=b.drugsid where a.drugsCount<b.drugsMin and drugsStorePlace='" + comboBox1.Text +"' order by a.Id";
                ds = op.getDataSet(sql);
                //report.DataSource = dt;
                report.DataSource = ds;
                //printTool.ShowPreview();
                //printTool.ShowRibbonPreview(UserLookAndFeel.Default);
                printTool.ShowRibbonPreview();
            }
            catch (Exception ex)
            {
                MessageBox.Show("无法打开报表，详细信息：" + ex.ToString());
            }
        }

        private void buttonPrint3_Click(object sender, EventArgs e)
        {
            try
            {

                XtraReport report = new XtraReport();
                string path = System.IO.Directory.GetCurrentDirectory();
                report.LoadLayout(path + "..\\..\\..\\Reports\\库存单报表.repx");
                ReportPrintTool printTool = new ReportPrintTool(report);
                //DataTable dt = new DataTable();
                DataSet ds = new DataSet();
                //string sql = "select user_id 编号,user_no 用户工号, user_name 用户姓名, user_power 用户权限, user_descripe 用户描述, user_sort 序号 from users order by user_sort";
                //dt = op.getDataTable(sql, "users");
                string sql = "select *,getdate() from drugsStore where drugsUsefulDate<(select getdate())  and drugsStorePlace='" + comboBox1.Text + "' order by Id";
                ds = op.getDataSet(sql);
                //report.DataSource = dt;
                report.DataSource = ds;
                //printTool.ShowPreview();
                //printTool.ShowRibbonPreview(UserLookAndFeel.Default);
                printTool.ShowRibbonPreview();
            }
            catch (Exception ex)
            {
                MessageBox.Show("无法打开报表，详细信息：" + ex.ToString());
            }
        }

        private void buttonAll1_Click(object sender, EventArgs e)
        {
            try
            {

                XtraReport report = new XtraReport();
                string path = System.IO.Directory.GetCurrentDirectory();
                report.LoadLayout(path + "..\\..\\..\\Reports\\库存单报表.repx");
                ReportPrintTool printTool = new ReportPrintTool(report);
                //DataTable dt = new DataTable();
                DataSet ds = new DataSet();
                //string sql = "select user_id 编号,user_no 用户工号, user_name 用户姓名, user_power 用户权限, user_descripe 用户描述, user_sort 序号 from users order by user_sort";
                //dt = op.getDataTable(sql, "users");
                string sql = "select *,getdate() from drugsStore  order by Id";
                ds = op.getDataSet(sql);
                //report.DataSource = dt;
                report.DataSource = ds;
                //printTool.ShowPreview();
                //printTool.ShowRibbonPreview(UserLookAndFeel.Default);
                printTool.ShowRibbonPreview();
            }
            catch (Exception ex)
            {
                MessageBox.Show("无法打开报表，详细信息：" + ex.ToString());
            }
        }

        private void buttonAll2_Click(object sender, EventArgs e)
        {
            try
            {

                XtraReport report = new XtraReport();
                string path = System.IO.Directory.GetCurrentDirectory();
                report.LoadLayout(path + "..\\..\\..\\Reports\\库存单报表.repx");
                ReportPrintTool printTool = new ReportPrintTool(report);
                //DataTable dt = new DataTable();
                DataSet ds = new DataSet();
                //string sql = "select user_id 编号,user_no 用户工号, user_name 用户姓名, user_power 用户权限, user_descripe 用户描述, user_sort 序号 from users order by user_sort";
                //dt = op.getDataTable(sql, "users");
                string sql = "select b.drugsMin ,a.*,getdate() from drugsstore a left outer join  drugswarning b on a.drugsid=b.drugsid where a.drugsCount<b.drugsMin  order by a.Id";
                ds = op.getDataSet(sql);
                //report.DataSource = dt;
                report.DataSource = ds;
                //printTool.ShowPreview();
                //printTool.ShowRibbonPreview(UserLookAndFeel.Default);
                printTool.ShowRibbonPreview();
            }
            catch (Exception ex)
            {
                MessageBox.Show("无法打开报表，详细信息：" + ex.ToString());
            }
        }

        private void buttonAll3_Click(object sender, EventArgs e)
        {
            try
            {

                XtraReport report = new XtraReport();
                string path = System.IO.Directory.GetCurrentDirectory();
                report.LoadLayout(path + "..\\..\\..\\Reports\\库存单报表.repx");
                ReportPrintTool printTool = new ReportPrintTool(report);
                //DataTable dt = new DataTable();
                DataSet ds = new DataSet();
                //string sql = "select user_id 编号,user_no 用户工号, user_name 用户姓名, user_power 用户权限, user_descripe 用户描述, user_sort 序号 from users order by user_sort";
                //dt = op.getDataTable(sql, "users");
                string sql = "select *,getdate() from drugsStore where drugsUsefulDate<(select getdate())  order by Id";
                ds = op.getDataSet(sql);
                //report.DataSource = dt;
                report.DataSource = ds;
                //printTool.ShowPreview();
                //printTool.ShowRibbonPreview(UserLookAndFeel.Default);
                printTool.ShowRibbonPreview();
            }
            catch (Exception ex)
            {
                MessageBox.Show("无法打开报表，详细信息：" + ex.ToString());
            }
        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataTable dt13 = new DataTable();
            string sql_13 = "select drugsId 药品ID,drugsName 药品名称, drugsPY 拼音码, drugsSpecification 药品规格,drugsUnit 计量单位, drugsCount 库存数量,drugsStorePlace 库存地址,drugsRegNum 批准文号 ,drugsFactory 生产厂家,providerCompany 供应商,drugsUsefulDate 有效期,drugsInPrice 进货价格,drugsSalePrice 销售价格 from drugsStore where drugsUsefulDate<(select getdate())  and drugsStorePlace='" + comboBox1.Text + "' order by Id";
            dt13 = op.getDataTable(sql_13, "drugsStore ");
            dataGridView1.DataSource = dt13;
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataTable dt12 = new DataTable();
            string sql_12 = "select a.drugsCount 库存数量,a.drugsStorePlace 库存地址,a.drugsId 药品ID,a.drugsName 药品名称, a.drugsPY 拼音码, a.drugsSpecification 药品规格,a.drugsUnit 计量单位,a.drugsRegNum 批准文号 ,a.drugsFactory 生产厂家,a.providerCompany 供应商,a.drugsUsefulDate 有效期,a.drugsInPrice 进货价格,a.drugsSalePrice 销售价格 from drugsstore a left outer join  drugswarning b on a.drugsid=b.drugsid where a.drugsCount<b.drugsMin and drugsStorePlace='" + comboBox1.Text + "' order by a.Id";
            dt12 = op.getDataTable(sql_12, "drugsStore ");
            dataGridView1.DataSource = dt12;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataTable dt11 = new DataTable();
            string sql_11 = "select drugsId 药品ID,drugsName 药品名称, drugsPY 拼音码, drugsSpecification 药品规格,drugsUnit 计量单位, drugsCount 库存数量,drugsStorePlace 库存地址,drugsRegNum 批准文号 ,drugsFactory 生产厂家,providerCompany 供应商,drugsUsefulDate 有效期,drugsInPrice 进货价格,drugsSalePrice 销售价格 from drugsStore where drugsStorePlace='" + comboBox1.Text + "' order by Id";
            dt11 = op.getDataTable(sql_11, "drugsStore ");
            dataGridView1.DataSource = dt11;
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataTable dt1_1 = new DataTable();
            string sql_1_1 = "select drugsId 药品ID,drugsName 药品名称, drugsPY 拼音码, drugsSpecification 药品规格,drugsUnit 计量单位, drugsCount 库存数量,drugsStorePlace 库存地址,drugsRegNum 批准文号 ,drugsFactory 生产厂家,providerCompany 供应商,drugsUsefulDate 有效期,drugsInPrice 进货价格,drugsSalePrice 销售价格 from drugsStore order by Id";
            dt1_1 = op.getDataTable(sql_1_1, "drugsStore ");
            dataGridView1.DataSource = dt1_1;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DataTable dt1_2 = new DataTable();
            string sql_1_2 = "select a.drugsCount 库存数量,a.drugsStorePlace 库存地址,a.drugsId 药品ID,a.drugsName 药品名称, a.drugsPY 拼音码, a.drugsSpecification 药品规格,a.drugsUnit 计量单位,a.drugsRegNum 批准文号 ,a.drugsFactory 生产厂家,a.providerCompany 供应商,a.drugsUsefulDate 有效期,a.drugsInPrice 进货价格,a.drugsSalePrice 销售价格 from drugsstore a left outer join  drugswarning b on a.drugsid=b.drugsid where a.drugsCount<b.drugsMin  order by a.Id";
            dt1_2 = op.getDataTable(sql_1_2, "drugsStore ");
            dataGridView1.DataSource = dt1_2;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DataTable dt1_3 = new DataTable();
            string sql_1_3 = "select drugsId 药品ID,drugsName 药品名称, drugsPY 拼音码, drugsSpecification 药品规格,drugsUnit 计量单位, drugsCount 库存数量,drugsStorePlace 库存地址,drugsRegNum 批准文号 ,drugsFactory 生产厂家,providerCompany 供应商,drugsUsefulDate 有效期,drugsInPrice 进货价格,drugsSalePrice 销售价格 from drugsStore where drugsUsefulDate<(select getdate())  order by Id";
            dt1_3 = op.getDataTable(sql_1_3, "drugsStore ");
            dataGridView1.DataSource = dt1_3;
        }

      
    }
}
